package com.luosan.portalservice.controller;

import com.luosan.portalservice.pojo.SubCard;
import com.luosan.portalservice.service.SubCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/cards/sub")
public class SubCardController {
    @Autowired
    private SubCardService subCardService;

    // 根据主菜单ID查询
    @GetMapping("/by-main/{mainCardId}")
    public List<SubCard> getByMainCardId(@PathVariable Integer mainCardId) {
        List<SubCard> result = subCardService.getByMainCardId(mainCardId);
        log.info(result.get(0).toString());
        return result;
    }

    // 批量保存子菜单
    @PostMapping("/batch")
    public String batchSave(@RequestBody List<SubCard> subCards) {
        return subCardService.saveBatch(subCards) ? "ok" : "保存失败";
    }
}
